Skip to content

Sublet address autocomplete#51

Merged
i30101 merged 6 commits into
masterfrom
andrew-validate-sublet-address
Mar 17, 2026
Merged

Sublet address autocomplete#51
i30101 merged 6 commits into
masterfrom
andrew-validate-sublet-address

Conversation

@i30101
Copy link
Copy Markdown
Collaborator

@i30101 i30101 commented Feb 9, 2026

Validate sublet addresses with OpenStreetMap
Screenshot 2026-02-08 at 7 07 29 PM

Copy link
Copy Markdown
Collaborator

@jamesdoh0109 jamesdoh0109 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work - left some comments. Im also wondering if there's an alternative to Nominatim because when i search, looks like some of the zipcodes are wrong (like my house has a different zipcode than 19104). Also the address formatting on the dropdown looks kinda weird (like in the screenshot you have, "4039, Walnuit Street, West Philadelphia, Philadelphia,..." seems a bit unnatural than just "4039 Walnut Street"

So ig unless there's a way to better parse the address (we dont even have to show zipcode tbh) from Nonimatim, might be better to look for alternative options (pelias looks pretty good)

Comment thread frontend/components/listings/address/AddressAutocomplete.tsx
Comment thread frontend/components/listings/address/AddressDropdown.tsx
Comment thread frontend/components/listings/form/SubletForm.tsx Outdated
Comment thread frontend/hooks/useAddressAutocomplete.ts Outdated
Comment thread frontend/components/listings/address/AddressAutocomplete.tsx
Comment thread frontend/lib/validations.ts Outdated
Comment thread frontend/lib/validations.ts Outdated
Comment thread frontend/lib/validations.ts Outdated
Comment thread frontend/components/listings/form/SubletForm.tsx Outdated
Comment thread frontend/hooks/useAddressAutocomplete.ts Outdated
Comment thread frontend/app/api/geocode/route.ts Outdated
Comment thread frontend/components/listings/form/SubletForm.tsx Outdated
Comment thread frontend/app/api/geocode/route.ts Outdated
Comment on lines +27 to +35
const search = (newQuery: string) => {
setQuery(newQuery);
};

const clearSuggestions = () => {
setQuery("");
setDebouncedQuery("");
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add useCallback to both of these functions. Right now search and clearSuggestions are plain inline functions, which means React creates brand new copies of them on every render. Even though the new copies do the same thing, React sees them as "different" (like two separate pieces of paper with the same words written on them). This matters because AddressAutocomplete.tsx` lists both functions in a useEffect dependency array, and because search and clearSuggestions are new references every render, React thinks the dependencies changed and re-runs the effect every single time - including after the user presses ArrowDown/ArrowUp to navigate the dropdown. That effect calls setHighlightedIndex(-1), which immediately resets the highlight back to nothing before the user can see it. This is why keyboard navigation in the address dropdown doesn't work at all. Wrapping both functions in useCallback makes React reuse the same function reference across renders, so the effect only re-runs when value or hasValidatedAddress actually change.

Comment thread frontend/components/listings/form/SubletForm.tsx
Copy link
Copy Markdown
Collaborator

@jamesdoh0109 jamesdoh0109 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, but good work overall!

https://github.com/user-attachments/assets/b86969be-072d-4154-a17b-81369d9b462c
Also, in the video above, when i unfocus with invalid address, it still tries to render the dropdown. I think the ideal behavior is to hide it on unfocus, but if the address is invaid, then disable submit button

@i30101 i30101 merged commit 60ad9fd into master Mar 17, 2026
5 checks passed
@i30101 i30101 deleted the andrew-validate-sublet-address branch March 17, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants